package main.java.com.chenchangjie.servlet;

import main.java.com.chenchangjie.eneity.User;
import main.java.com.chenchangjie.service.UserService;
import main.java.com.chenchangjie.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String password = req.getParameter("password");
        User user = (User) userService.Login(name,password);
        if(user == null)
            resp.sendRedirect("/login.jsp");
        else{
            req.getSession().setAttribute("user",user);
            resp.sendRedirect("/productList");
        }
    }
}
